package com.mp3s.db_sqlite_pool.utils;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import com.mp3s.interface3.QuoteDataQueue;

public class WriteTaskQueue {
private static final BlockingQueue<QuoteDataQueue> queue = new LinkedBlockingQueue<>();

    // 添加写任务
    public static void addWriteTask(QuoteDataQueue value) {
        queue.offer(value);
    }

    // 处理写任务
    public static void processWriteTasks() {
        while (true) {
            try {
                QuoteDataQueue value = queue.take(); // 从队列中取出任务
                if(value != null)
                {
                    sqliteImplpool.writeData(value); // 执行写操作
                }

            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
        }
    }
}
